<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String contextPath = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户组管理</title>
<jsp:include page="/inc/inc.jsp" />
<script type="text/javascript"
	src="<%=contextPath %>/jframe/sso/list/js/userGroupList.js"></script>
<script type="text/javascript">
var contextPath = '<%=contextPath%>';
var action = 'userGroupAction';
$(function(){
	<%=request.getAttribute("js")%> 		
/* 	var pager = $('#grid').datagrid('getPager');    // 得到datagrid的pager对象  
    pager.pagination({    
        showPageList:false,
        buttons:[{
					iconCls:'icon-add',
					handler:function(){
						$('#grid').datagrid('endEdit', lastIndex);
						$('#grid').datagrid('appendRow',{							
						});
						lastIndex = $('#grid').datagrid('getRows').length-1;
						$('#grid').datagrid('selectRow', lastIndex);
						$('#grid').datagrid('beginEdit', lastIndex);
					}
				},{
					iconCls:'icon-remove',
					handler:function(){
						var row = $('#grid').datagrid('getSelected');
						if (row){
							var index = $('#grid').datagrid('getRowIndex', row);
							$('#grid').datagrid('deleteRow', index);
						}
					}
				},{
					iconCls:'icon-save',
					handler:function(){
						var changes = $('#grid').datagrid('getChanges');		
						alertInfo(obj2json(changes));
						$('#grid').datagrid('acceptChanges');
					}
				},{
					iconCls:'icon-undo',
					handler:function(){
						$('#grid').datagrid('rejectChanges');
					}
				},{
					iconCls:'icon-search',
					handler:function(){
						var rows = $('#grid').datagrid('getChanges');
						alert('changed rows: ' + rows.length + ' lines');
					}
				}]
    });  */   
}); 

function add(){
	showWin('新增',contextPath+'/jframe/sso/edit/userGroupEdit.jsp?id=0',400,350);
}

function edit(){
	var rows = $('#grid').datagrid('getSelections');
	if(rows.length>1){
		alertWarn("请您只选择一条记录进行操作！");
		return;
	}else if(rows.length==0){
		alertError("请您选择要操作的记录！");
		return;
	}
	var id = getSelection();
	showWin('编辑',contextPath+'/jframe/sso/edit/userGroupEdit.jsp?id='+id,400,350);
}

function del(){
	var ids = getSelections();
	if(ids==""){
		alertError("请您选择要操作的记录！");
		return;
	}else{
		econfirm('警告','确定要删除所选择的数据？',function(r){
    		if(r){
    			var url = action+".do?method=delete";
    			$.ajax({
    				url:url,
    		 		type: 'post',
    			    data:{
    			    	ids:ids
    			    },
    			    dataType: 'json',
    			    error: function(){
    			        alertError('删除失败!');
    			    },
    			    success: function(data){
    			    	alertInfo('成功删除所选记录！');
    			    	$('#grid').datagrid('reload');
    			    }
    			});
    		}
    	});
		$('#grid').datagrid('clearSelections');
	}	
}

function find(){
	var vo=[];
	var name = $('#name').val();
	var active = $('#active').combobox('getValue');
	if(name!=null&&name!="")
		vo.push({name:'name',type:'String',logic:'and',operators:'like',value:name});
	if(active!=null&&active!="")
		vo.push({name:'active',type:'int',logic:'and',operators:'=',value:active});		
    $('#grid').datagrid('load',{
       conditions: obj2json(vo)
   });
}

</script>
</head>
<body>
	<div id="tb">
	     <a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>
		 <a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
		 <a class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a><br>
		 <span>名称：</span><input id="name" name="name" type="text" style="width: 100px;">
		 <span>有效否：</span>
		 <select id="active" name="active" class="easyui-combobox" style="width:100px;">
		  <option value=""></option>
		  <option value="1">有效</option>
		  <option value="0">无效</option>
		</select>
		 <a class="easyui-linkbutton" plain="true" onclick="find()" iconCls="icon-search">查询</a>
	</div>
	<table id="grid" toolbar="#tb" border="0"></table>
</body>
</html>